<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of tfFormInput
 *
 * @author waterfrog
 */
if(!defined('TinyFW')) exit('Access denied!');

class tfFormInput extends tfFormElement {

    private $_type  =   null;

    

    public function  __construct($type, $name='', $id='', $caption='', $value='', $attr_arr = '') {
        $this->_set_type($type);
        $this->setName($name);
        $this->setId($id);
        $this->setCaption($caption);

        $this->setValue($value);

        if(!empty($attr_arr)) {
            $this->setAttr($attr_arr);
        }
        
    }


    private function _set_type($type) {
        
        $type = strtolower($type);
        
        $valid_types = array(
                    'text',
                    'password',
                    'checkbox',
                    'radio',
                    'submit',
                    'reset',
                    'file',
                    'hidden',
                    'image',
                    'button',
                    );
        
        if(in_array($type, $valid_types)) {
            $this->_type = $type;
        } else {
            $this->_type = "text";
        }

    }

    public function getType() {
        return $this->_type;
    }

    public function isHidden() {
        if($this->_type == "hidden") {
            return true;
        } else {
            return false;
        }

    }

    //显示元素
    public function render() {
        
        return "<input type='" . $this->getType() . "' name='" . $this->getName() . "' value='" . $this->getValue() . "' id='" . $this->getId() . "'  " . $this->getAttrStr() . "/>\r\n";
    }

    /*
    public function  __toString() {
        $this->render();
    }
    */

    
}
?>
